﻿using System.Collections.ObjectModel;
using System.Diagnostics;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;

namespace NextSampleApp.ViewModel
{
    public class MainViewModel : ViewModelBase
    {
        #region Fields
        private ObservableCollection<string> _imageUrls = new ObservableCollection<string>();
        private int _selectedIndex;
        #endregion

        #region Constructor
        public MainViewModel()
        {
            _imageUrls.Add("http://img.geilicdn.com/taobao15303909888_146x219.jpg");
            _imageUrls.Add("http://img.geilicdn.com/taobao18731040035_159x168.jpg");
            _imageUrls.Add("http://img.geilicdn.com/taobao18805908427_146x194.jpg");
            _imageUrls.Add("http://img.geilicdn.com/taobao14270048486_146x201.jpg");
            _imageUrls.Add("http://img.geilicdn.com/taobao18677912875_168x168.jpg");
            this.SelectionChangedCommand = new RelayCommand(SelectionChangedExecute);
        }
        #endregion

        #region Properties
        public ObservableCollection<string> ImageUrls
        {
            get { return _imageUrls; }
            set
            {
                if (value != _imageUrls)
                {
                    _imageUrls = value;
                    this.RaisePropertyChanged(() => this.ImageUrls);
                }
            }
        }

        public int SelectedIndex
        {
            get { return _selectedIndex; }
            set
            {
                _selectedIndex = value;
                this.RaisePropertyChanged(() => this.SelectedIndex);
            }
        }
        #endregion

        #region Command
        public RelayCommand SelectionChangedCommand { get; private set; }
        #endregion

        #region Method
        private void SelectionChangedExecute()
        {
            Debug.WriteLine("索引:" + SelectedIndex);
        }
        #endregion
    }
}